$(function ()
{
    $("table").DataTable({
        "oLanguage" : {
            "sLengthMenu" : "每页显示 _MENU_ 条记录",
            "sZeroRecords" : "抱歉， 没有找到",
            "sInfo" : "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
            "sInfoEmpty" : "没有数据",
            "sInfoFiltered" : "(从 _MAX_ 条数据中检索)",
            "oPaginate" : {
                "sFirst" : "首页",
                "sPrevious" : "前一页",
                "sNext" : "后一页",
                "sLast" : "尾页"
            },
            "sZeroRecords" : "没有检索到数据"
        },
        "bScrollCollapse" : true,
        "bProcessing" : true,
        "serverSide" : true,
        "dom" : '<"toolbar">rtilp',
        "ajax" : {
            "url" : adminBasePath + "menu/list",
            "type" : "POST"
        },
        columns : [
            {
                data : 'id',
                title : "ID"
            },
            {
                data : 'name',
                title : "名称"
            },
            {
                data : 'type',
                title : "类型"
            },
            {
                data : 'url',
                title : "链接"
            },
            {
                data : 'permission',
                title : "权限"
            }
        ]
    });

    var toolbarHtml = [];
    toolbarHtml.push("<p>");
    toolbarHtml.push("<button type=\"button\" class=\"btn btn-success\" btnId='add' >增加</button> ");
    toolbarHtml.push("<button type=\"button\" class=\"btn btn-warning\" btnId='modify'>修改</button> ");
    toolbarHtml.push("<button type=\"button\" class=\"btn btn-danger\" btnId='delete'>删除</button> ");
    toolbarHtml.push("</p>");

    $("div.toolbar").html(toolbarHtml.join(""));

    $("div.toolbar").find("button").bind("click", function ()
    {
        var btnId = $(this).attr("btnId");

        switch(btnId)
        {
            case 'add':
                window.location.href = adminBasePath + "menu/newMenu";
                break;
        }
    });

    $("tbody").on('click', 'tr', function ()
    {
        if ($(this).hasClass('selected'))
        {
            $(this).removeClass('selected');
        }
        else
        {
            table.$('tr.selected').removeClass('selected');
            $(this).addClass('selected');
        }
    });
});